package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.dao.FilmMapper;
import com.example.entity.Film;
import com.example.service.FilmService;
import com.example.vo.FilmDetailVo;
import com.example.vo.FilmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;


@Service
public class FilmServiceImpl implements FilmService {

    @Autowired
    private FilmMapper filmMapper;

    @Override
    public List<FilmVo> selectAll() {
        List<Film> films = filmMapper.getList();
        System.out.println("数据库中影片数量：" + films.size());

        List<FilmVo> result = new ArrayList<>();
        for (Film film : films) {
            FilmVo vo = new FilmVo();
            vo.setFilmId(film.getFilmId());
            vo.setName(film.getName());
            vo.setDirector(film.getDirector());
            vo.setImgPath(film.getImgPath());

           // System.out.println(film.getFilmId()+"=========="+film.getImgPath());
            result.add(vo);
        }
        return result;
    }

    @Override
    public FilmDetailVo findFilmById(String filmId) {
        Film film = filmMapper.getFilmById(filmId);
        FilmDetailVo vo = new FilmDetailVo();
        vo.setFilmId(filmId);
        vo.setName(film.getName());
        vo.setDirector(film.getDirector());
        vo.setImgPath(film.getImgPath());
        vo.setType(film.getType());
        vo.setPlayer(film.getPlayer());
        vo.setSynopsis(film.getSynopsis());
        vo.setCountry(film.getCountry());
        vo.setLength(film.getLength());

        return vo;
    }

    @Override
    public List<Film> searchFilm(String filmName) {
        QueryWrapper<Film> filmQueryWrapper=new QueryWrapper<>();
        filmQueryWrapper.like("name",filmName);
        List<Film> filmList=filmMapper.selectList(filmQueryWrapper);
        return filmList;
    }

    @Override
    public List<Film> selectAllFilm() {
        List<Film> films = filmMapper.getList();
        List<Film> result = new ArrayList<>();
        for (Film film : films) {
            Film f = new Film();
            f.setFilmId(film.getFilmId());
            f.setName(film.getName());
            f.setDirector(film.getDirector());
            f.setImgPath(film.getImgPath());
            f.setPlayer(film.getPlayer());
            f.setType(film.getType());
            result.add(f);
        }
        return result;

    }

    @Override
    public List<Film> selectFilmByCinemaId(String cinemaId) {
        QueryWrapper<Film> filmQueryWrapper=new QueryWrapper<>();
        filmQueryWrapper.like("cinema_id",cinemaId);
        List filmList=filmMapper.selectList(filmQueryWrapper);
        return filmList;
    }


}
